﻿/// <reference path="/Scripts/jquery-1.4.1-vsdoc.js"/>
/// <reference path="/Scripts/vsdoc/GMAPJSHelper_Release.js"/>
function GoogleMaps() { }

GoogleMaps.mapDivId = 'mainMap';
GoogleMaps.emap = null;
GoogleMaps.points = [];
GoogleMaps.geocoder = null;

GoogleMaps.LoadMap = function () {
    if (GBrowserIsCompatible()) {
        GoogleMaps.emap = new GMap2(document.getElementById(GoogleMaps.mapDivId));
        GoogleMaps.emap.setUIToDefault();
        GoogleMaps.emap.setCenter(new GLatLng(37.4419, -122.1419), 13);
        GoogleMaps.emap.setUIToDefault();
        GEvent.addListener(GoogleMaps.emap, "zoomend", function (oldzoom, zoom) {
            $("#Map_Zoom").val(zoom);
        });
        GoogleMaps.geocoder = new GClientGeocoder();
    }
}

GoogleMaps.FindAddress = function (address) {
    GoogleMaps.geocoder.getLocations(address, GoogleMaps.AddAddressToMap);
}

GoogleMaps.AddAddressToMap = function (response) {
    GoogleMaps.emap.clearOverlays();
    if (!response || response.Status.code != 200) {
        alert("address not found");
    } else {
        place = response.Placemark[0];
        point = new GLatLng(place.Point.coordinates[1],
                            place.Point.coordinates[0]);
        marker = new GMarker(point);
        GoogleMaps.emap.addOverlay(marker);
        marker.openInfoWindow(place.address);
        GoogleMaps.SetLocationToForm(place.address, point.lat(), point.lng());
    }
}

GoogleMaps.SetLocationToForm = function (address, latitude, longitude) {
    $("#Map_Address").val(address);
    $("#Map_Latitude").val(latitude.toString());
    $("#Map_Longitude").val(longitude.toString());
    $("#Map_Zoom").val(GoogleMaps.emap.getZoom());
}


